package zaplog

import (
	"github.com/lestrrat-go/file-rotatelogs"
	"go.uber.org/zap/zapcore"
	"path"
	"store/global"
	"time"
)

type _logs struct {
}

var Logs = new(_logs)

func (f *_logs) GetWriteSyncer(level string) (zapcore.WriteSyncer, error) {
	fileWriter, err := rotatelogs.New(
		//生成动态日志路径及日志文件
		path.Join(global.Config.App.LogPath, "%Y-%m-%d", level+".log"),
		rotatelogs.WithClock(rotatelogs.Local),
		rotatelogs.WithMaxAge(time.Duration(7)*24*time.Hour),
		rotatelogs.WithRotationTime(time.Hour*24),
	)
	//将 fileWriter 转换为 zapcore.WriteSyncer 接口，使 Zap 日志库能够将日志内容写入配置的文件
	return zapcore.AddSync(fileWriter), err
}
